home *** CD-ROM | disk | FTP | other *** search
/ Champak 125 / Vol 125 (Damaged).iso / games / rabbit_r.swf / scripts / __Packages / smashing / IntervalEngine.as next >
Encoding:
Text File  |  2009-06-09  |  1.9 KB  |  73 lines

  1. class smashing.IntervalEngine
  2. {
  3.    var _uo;
  4.    var _uf;
  5.    var _update_interval;
  6.    var _last_update;
  7.    var _i;
  8.    var _ft;
  9.    var _el;
  10.    var _MAX_TIMEDIFF = 0.005;
  11.    var _MIN_FPS = 5;
  12.    var _MAX_FRAMETIME = 1 / smashing.IntervalEngine.prototype._MIN_FPS;
  13.    var _lel = 0.2;
  14.    var _FPS = 0;
  15.    function IntervalEngine(update_object, update_function)
  16.    {
  17.       this._uo = update_object;
  18.       this._uf = update_function;
  19.    }
  20.    function startFlat(FPS)
  21.    {
  22.       this._FPS = FPS;
  23.       this._update_interval = 1 / FPS;
  24.       this._last_update = getTimer() * 0.001;
  25.       this._i = setInterval(this,"_flat_step",0);
  26.    }
  27.    function startFlex()
  28.    {
  29.       this._last_update = getTimer() * 0.001;
  30.       this._i = setInterval(this,"_flex_step",0);
  31.    }
  32.    function startFast()
  33.    {
  34.       this._last_update = getTimer();
  35.       this._i = setInterval(this,"_fast_step",10);
  36.    }
  37.    function reset(Void)
  38.    {
  39.       if(this._i != undefined)
  40.       {
  41.          clearInterval(this._i);
  42.       }
  43.       this._ft = 0;
  44.       this._last_update = getTimer() * 0.001;
  45.       this._lel = this._MAX_FRAMETIME / 2;
  46.    }
  47.    function _flex_step(Void)
  48.    {
  49.       this._el = Math.min(this._MAX_FRAMETIME,- this._last_update + (this._last_update = getTimer() * 0.001));
  50.       this._lel -= Math.max(- this._MAX_TIMEDIFF,Math.min(this._MAX_TIMEDIFF,this._lel - this._el));
  51.       this._uo[this._uf](this._lel);
  52.    }
  53.    function _flat_step(Void)
  54.    {
  55.       this._ft += - this._last_update + (this._last_update = getTimer() * 0.001);
  56.       if(this._ft < this._update_interval)
  57.       {
  58.          return undefined;
  59.       }
  60.       this._uo[this._uf](this._ft);
  61.       this._ft = 0;
  62.    }
  63.    function _fast_step(Void)
  64.    {
  65.       this._el = - this._last_update + (this._last_update = getTimer());
  66.       this._uo[this._uf](this._el * 0.001);
  67.    }
  68.    function clear()
  69.    {
  70.       clearInterval(this._i);
  71.    }
  72. }
  73.